package com.car.controller;

import com.car.entity.User;
import com.car.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpSession;

@Controller("userController")
public class UserController {
    @Autowired
    @Qualifier("userService")
    private IUserService userService;

    @RequestMapping(value = "/findUser",method = RequestMethod.POST)
    public String findUser(String uname, String password, Model model, HttpSession session){
        User u = userService.findUser(uname, password);
//        if(!"".equals(u) && u!=null ){
        if(u.getUname().equals("tom")){
            System.out.println("登录成功");
            model.addAttribute("u",u);
            session.setAttribute("u",u);
            return "redirect:/index.jsp";
        }if (u.getUname().equals("张三")){
            System.out.println("登录成功");
            model.addAttribute("u",u);
            session.setAttribute("u",u);
            return "redirect:/bosssystem/index.jsp";
        }else{
            System.out.println("登录失败");
            return "redirect:login.jsp";
        }

    }
}
